<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>

		<link rel="stylesheet" type="text/css" href="layui/css/layui.css" />
	</head>
	<body>
		<!-- <form action="" method="post"> -->


		<div class="layui-card">
			<div class="layui-card-header">修改密码</div>
			<div class="layui-card-body" pad15="">

				<div class="layui-form" lay-filter="">
					<div class="layui-form-item">
						<label class="layui-form-label">当前密码</label>
						<div class="layui-input-inline">
							<input type="password" name="oldPassword" lay-verify="required" lay-vertype="tips" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">新密码</label>
						<div class="layui-input-inline">
							<input type="password" name="password" lay-verify="pass" lay-vertype="tips" autocomplete="off" id="LAY_password"
							 class="layui-input">
						</div>
						<div class="layui-form-mid layui-word-aux">6到16个字符</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">确认新密码</label>
						<div class="layui-input-inline">
							<input type="password" name="repassword" lay-verify="repass" lay-vertype="tips" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit="" lay-filter="setmypass">确认修改</button>
						</div>
					</div>
				</div>

			</div>
		</div>
		<!-- </form> -->
		<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			//获取表单区域所有值
			layui.use(["form"], function() {
				var form = layui.form,
					$ = layui.jquery;

				form.on('submit(setmypass)', function(data) {
					// console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
					// console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
					console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
					if (data.field.password == '' || data.field.repassword == '') {
						layer.msg("请填写完整信息", {
							time: 1000
						})
						return false;
					}
					if (data.field.password !== data.field.repassword) {
						layer.msg("两次密码不一致", {
							time: 1000
						})
						return false;
					}
					
					
					// layer.alert('修改密码成功，请重新登录', {
					// 	icon: 1,
					// 	title: "提示",
					// 	yes:function(){
					// 		parent.location.reload();
					// 	},
					// 	cancel:function(){
					// 		parent.location.reload();
					// 	}
					// });
					
					$.post("up", data.field, function(resp) {
						console.log(resp)
						if (resp.code == 200) {
							layer.alert('修改密码成功，请重新登录', {
								icon: 1,
								title: "提示",
								yes:function(){
									parent.location.reload();
								},
								cancel:function(){
									parent.location.reload();
								}
							});
						}else{
							layer.msg(resp.msg,{time:1000})
						}
					})

					return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
				});
			})
		</script>
	</body>
</html>
